Flatten nested objects keeping the properties of parents